﻿using Config;
using gfLibrary;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBUtility;
using System.Drawing;
using IYAKASAPortal.Tools;

namespace IYAKASAPortal.LabourVerify
{
    public partial class VehicleDD : System.Web.UI.Page
    {
        private int m_lineNum;

        protected void Page_Load(object sender, EventArgs e)
        {
     
            if (Request["LineNum"] != null && !string.IsNullOrEmpty(Request["LineNum"]))
            {
                if (!int.TryParse(Request["LineNum"].ToString(), out m_lineNum))
                {
                    m_lineNum = 1;
                }
            }
            else
            {
                m_lineNum = 1;
            }

            AddLineButton();

            DDSocket.GetInstance().SendDDMsg(m_lineNum);
            
            if (Page.IsPostBack == false)
            {
            }

            foreach (var item in btnContainer.Controls)
            {
                if (item is LinkButton)
                {
                    ((LinkButton)item).ForeColor = Color.White; 
                    if (((LinkButton)item).Text.Substring(0, 1) == m_lineNum.ToString())
                    {
                        ((LinkButton)item).BackColor = Color.FromArgb(61, 187, 43);
                        
                    }
                }
            }

        }

        private void AddLineButton()
        {
            DataTable dt = new DataTable();
            string sql = string.Format("SELECT LINE_ID FROM  INSPECTION_LINE_INFO GROUP BY LINE_ID");
            DbHelper.GetTable(sql, ref dt);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                LinkButton btn = new LinkButton();
                btn.Text = string.Format("{0}号检测线", dt.Rows[i]["LINE_ID"]);
                btn.CssClass = "y_link_button";
                btn.Click += LinkButton1_Click;
                btnContainer.Controls.Add(btn);
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            LinkButton btn = (LinkButton)sender;
            if (btn != null)
            {
                string val = btn.Text.Substring(0, 1);
                gfAjaxJs.SetGoToUrl(this.UpdatePanel1, string.Format("VehicleDD.aspx?LineNum={0}", val));
            }
        }
    }
       
}